<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        #nav{
            width: 200px;
            border: 1px solid #ccc;
            box-shadow: 3px 3px 2px #ddd;
            position: absolute;
            top:10px;
            left:10px;
            background-color: #fff;
            display: none;
        }
        #nav li{
            height: 40px;
            line-height: 40px;
            padding: 0 20px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <h1>JS 自定义菜单</h1>
    <hr>

    <ul id="nav">
        <li>复制</li>
        <li>粘贴</li>
        <li>剪切</li>
        <li>刷新</li>
        <li>用迅雷下载.</li>
        <li>用快播打开.</li>
    </ul>

    <script>
    var nav = document.getElementById('nav');
    // 右击出现
    document.oncontextmenu = function (en) {
        var en = en || window.event;
        // console.log(en);
        var x = en.clientX;
        var y = en.clientY;
        console.log(x,y);

        document.title = 'X: '+x + ',Y:'+y;

        // 改变元素的位置
        nav.style.left = x + 'px';
        nav.style.top = y + 'px';

        nav.style.display = 'block';
        return false;
    }

    // 左键取消
    document.onclick = function () {
        nav.style.display = 'none';
    }

    // hover效果
    var lis = nav.getElementsByTagName('li');
    // 循环绑定事件
    for (var i = 0; i < lis.length; i++) {
        lis[i].onmouseover = function (){
            this.style.backgroundColor = '#abcdef';
        }
        lis[i].onmouseout = function (){
            this.style.backgroundColor = '#fff';
        }
    }

    </script>
</body>
</html>